from dependency_injector import containers, providers

from api.fm.configs import ConfigManager
from api.fm.extensions.ext_db import DatabaseManager
from api.fm.extensions.ext_llm import LLM
from api.fm.extensions.ext_logger import LoggerManager


# 4. IoC 容器配置
class Container(containers.DeclarativeContainer):
    # 注入配置对象
    config = providers.Singleton(ConfigManager)

    # 注入 Logger 对象，传入配置对象
    logger = providers.Singleton(LoggerManager, config_manager=config)

    # 注入数据库管理对象，传入配置对象
    db_manager = providers.Singleton(DatabaseManager, config_manager=config)

    llm = providers.Singleton(LLM, config_manager=config)


def get_container() -> Container:
    container = Container()
    container.config()
    container.logger()
    return container
